<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m180927_080957_db_init
 */
class m180927_080957_db_init extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

        // 团队信息
        $this->createTable('product', [

            "id" =>             Schema::TYPE_PK,
            "customer_id" =>    Schema::TYPE_INTEGER."(11) DEFAULT '0' COMMENT '客户ID'",
            "name" =>           Schema::TYPE_STRING. "(255) NOT NULL COMMENT '团名称'",
            "code" =>           Schema::TYPE_STRING. "(255) NOT NULL COMMENT '团号'",

            "p_name" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '联系人姓名'",
            "p_phone" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '联系人电话'",
            "p_mail" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '联系人邮箱'",
            "p_department" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '联系人部门'",

            "city" =>        Schema::TYPE_STRING. "(255) NULL COMMENT '目的地城市(多个)'",

            "begin_date" =>      Schema::TYPE_DATE. " NULL COMMENT '抵达日期' ",
            "end_date" =>       Schema::TYPE_DATE. " NULL COMMENT '离开日期'",

            "num" =>            Schema::TYPE_INTEGER. "(7) DEFAULT '0' COMMENT '团人数'",
            
            "colse_date" =>     Schema::TYPE_DATE. " NULL COMMENT '关团时间'",

            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1 报价 2成团 3执行 4关团 10取消'",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",

            "oper_id" =>   Schema::TYPE_STRING. "(255) NULL COMMENT '指定操作ID(多个)'",

            "currency" =>   Schema::TYPE_INTEGER. "(2) DEFAULT '1' COMMENT '货币(美元)'",

            "price" => Schema::TYPE_DECIMAL.   "(10,2) DEFAULT '0.00' COMMENT '总收入' ",

            "cost_price"    =>  Schema::TYPE_DECIMAL.   "(10,2) DEFAULT '0.00' COMMENT '总成本' ",

            "file_path" => Schema::TYPE_STRING. "(255) NULL COMMENT '第一次报价单'",
            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间' ",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

        // 团队报价单上传信息
        $this->createTable('product_log', [
            "id" =>             Schema::TYPE_PK,
            "product_id" =>     Schema::TYPE_INTEGER."(11) DEFAULT '0' COMMENT '团队ID'",
            "file_path" =>      Schema::TYPE_STRING. "(255) NULL COMMENT '报价单'",
            "num" =>           Schema::TYPE_INTEGER.   "(10) DEFAULT '1' COMMENT '次数'",
            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1 正常 2 禁止'",
            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",
            "currency" =>   Schema::TYPE_INTEGER. "(2) DEFAULT '1' COMMENT '货币(美元)'",
            "price" => Schema::TYPE_DECIMAL.   "(10,2) DEFAULT '0.00' COMMENT '记录总收入' ",
            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间' ",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 成本项
        $this->createTable('cost', [
            "id" =>             Schema::TYPE_PK,
            "product_id" =>     Schema::TYPE_INTEGER.   "(10) NOT NULL DEFAULT '0' COMMENT '团队ID'",

            "cost_type" =>     Schema::TYPE_INTEGER.  "(10) NOT NULL DEFAULT '0' COMMENT '成本项类型'",

            "supplier_id" =>     Schema::TYPE_INTEGER.  "(10) NOT NULL DEFAULT '0' COMMENT '供应商ID'",

            "payment" => Schema::TYPE_INTEGER.  "(10) NOT NULL DEFAULT '0' COMMENT '支付方式'",

            "day_num" => Schema::TYPE_INTEGER.  "(10)  DEFAULT '0' COMMENT '间夜'",

            "currency" =>   Schema::TYPE_INTEGER. "(2) DEFAULT '1' COMMENT '货币(美元)'",

            "price" => Schema::TYPE_DECIMAL.   "(10,2) DEFAULT '0.00' COMMENT '成本' ",

            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2 禁用 '",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",

            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间'",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 客户管理
        $this->createTable('customer', [
            "id" =>             Schema::TYPE_PK,
    
            "name" =>           Schema::TYPE_STRING.    "(255) NOT NULL COMMENT '公司名称'",
            "en_name" =>       Schema::TYPE_STRING.    "(255) NOT NULL COMMENT '英文名称'",

            "address" =>        Schema::TYPE_STRING.    "(255) NOT NULL COMMENT '公司地址'",
            "en_address" =>        Schema::TYPE_STRING.    "(255) NOT NULL COMMENT '英文公司地址'",

            "person" =>           Schema::TYPE_STRING.    "(32)  NULL COMMENT  '联系人姓名'",
            "en_person" =>           Schema::TYPE_STRING.    "(32)  NULL COMMENT  '英文联系人姓名'",

            "job" =>           Schema::TYPE_STRING.    "(64)  NULL COMMENT  '职务'",

            "en_job" =>           Schema::TYPE_STRING.    "(64)  NULL COMMENT  '职务英文'",

            "phone" =>          Schema::TYPE_STRING.    "(32)  NULL COMMENT  '联系电话'",

            "day_time" =>     Schema::TYPE_STRING.    "(64)  NULL COMMENT  '付款天数'",

            "remark" =>        Schema::TYPE_STRING.    "(512)  NULL COMMENT '备注'",

            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",
            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间'",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 供应商管理
        $this->createTable('supplier', [
            "id" =>             Schema::TYPE_PK,
            "type" =>           Schema::TYPE_INTEGER.   "(2) DEFAULT '0' COMMENT '供应商类型'",
            "en_name" =>   Schema::TYPE_STRING.    "(255) NOT NULL COMMENT '英文名称'",
            
            "hotel_group" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '酒店集团' ",            
            "is_tour" =>  Schema::TYPE_INTEGER.   "(1) DEFAULT '1' COMMENT '是否导游' ",     
            "phone" =>          Schema::TYPE_STRING.    "(32)  NULL COMMENT  '导游联系电话'",

            "city" =>           Schema::TYPE_STRING.    "(255)  NULL COMMENT  '城市'",
            "remark" =>        Schema::TYPE_STRING.    "(512)  NULL COMMENT '备注'",

            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",
            "created_at" =>     Schema::TYPE_DATETIME.  " NULL COMMENT '创建时间'",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);



    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m180927_080957_db_init cannot be reverted.\n";

        $this->dropTable('product');
        $this->dropTable('product_log');
        $this->dropTable('cost');
        $this->dropTable('customer');
        $this->dropTable('supplier');

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m180927_080957_db_init cannot be reverted.\n";

        return false;
    }
    */
}
